package com.yxinsur.imc.web.controller.business;

import com.yxinsur.imc.business.form.SupplierExpenseForm;
import com.yxinsur.imc.business.service.IImcSupplierExpenseService;
import com.yxinsur.imc.business.vo.ImcSupplierExpenseVo;
import com.yxinsur.imc.common.annotation.Log;
import com.yxinsur.imc.common.core.controller.BaseController;
import com.yxinsur.imc.common.core.domain.AjaxResult;
import com.yxinsur.imc.common.core.page.TableDataInfo;
import com.yxinsur.imc.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 供应商-费用科目Controller
 *
 * @author imc
 * @date 2021-07-29
 */
@Api(value = "6.2.供应商-费用科目接口服务", tags = {"6.2.供应商-费用科目模块接口服务"})
@RestController
@RequestMapping("/business/expense/supplier")
public class ImcSupplierExpenseController extends BaseController {
    @Autowired
    private IImcSupplierExpenseService imcSupplierExpenseService;

    /**
     * 供应商费用科目-查询列表
     */
    @ApiOperation("供应商费用科目-查询列表")
    @GetMapping("/list")
    public TableDataInfo list(SupplierExpenseForm supplierExpenseForm) {
        startPage();
        List<ImcSupplierExpenseVo> list = imcSupplierExpenseService.selectImcSupplierExpenseList(supplierExpenseForm);
        return getDataTable(list);
    }

    /**
     * 供应商费用科目-查询详请
     */
    @ApiOperation("供应商费用科目-查询详请")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(imcSupplierExpenseService.selectImcSupplierExpenseById(id));
    }

    /**
     * 供应商费用科目-新增
     */
    @ApiOperation("供应商费用科目-新增")
    @Log(title = "供应商费用科目-新增", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody SupplierExpenseForm supplierExpenseForm) {
        return this.imcSupplierExpenseService.insertImcSupplierExpense(supplierExpenseForm);
    }

    /**
     * 供应商费用科目-修改
     */
    @ApiOperation("供应商费用科目-修改")
    @Log(title = "供应商费用科目-修改", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody SupplierExpenseForm supplierExpenseForm) {
        return imcSupplierExpenseService.updateImcSupplierExpense(supplierExpenseForm);
    }

    /**
     * 供应商费用科目-删除
     */
    @ApiOperation("供应商费用科目-删除")
    @Log(title = "供应商-费用科目-删除", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete/{id}")
    public AjaxResult remove(@PathVariable String id) {
        return toAjax(imcSupplierExpenseService.deleteImcSupplierExpenseById(id));
    }
}
